﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace GrayParrot.Web.Formly
{
    public class OptionsTemplateOptionsAttribute : TemplateOptionsAttribute
    {
        /// <summary>
        /// Gets or sets the options.
        /// </summary>
        /// <value>
        /// Is an array of options for the multiCheckbox form field to display. Each option should be an object.
        /// </value>
        /// <remarks>
        /// The option object must be in the form:
        /// { 
        ///   name:,
        ///   value:
        /// }
        /// 
        /// Example:
        /// options: [{vlaue: 1, name : "Administrator"}, {value: 2, name : "User"}]
        /// 
        /// The option object propertis are mandatory and the name is fixed to:
        /// id: is the value for the option;
        /// title: is the text shown to the user;
        /// </remarks>
        [JsonProperty(PropertyName = "options")]
        public List<object> Options { get; set; }

        /// <summary>
        /// Gets or sets the callback.
        /// </summary>
        /// <value>
        /// The callback used for async options...
        /// </value>
        /// <remarks>
        /// This callback is used to load async the option objects to set the options property.
        /// </remarks>
        /// <example>
        /// Define the callback like this:
        /// 
        /// Callback="NameOfTheCallback($Scope, NameOfTheDataServiceThatLoadsData)"
        /// 
        /// In the Angular definition we have a Service named NameOfTheDataServiceThatLoadsData,
        /// and in the script section of the page we have a function like this:
        /// 
        /// function NameOfTheCallback($scope, NameOfTheDataServiceThatLoadsData) {
        ///    NameOfTheDataServiceThatLoadsData.getData().then(function(data){
        ///    // for example data is : [{value: 1, name : "Administrator"}, {value: 2, name : "User"}]
        ///    $scope.to.options = data;
        /// });
        /// </example>
        [JsonProperty(PropertyName = "callback")]
        public string Callback { get; set; }

        [JsonProperty(PropertyName = "dependsBy")]
        public string DependsBy { get; set; }

        /// <summary>
        /// Gets or sets the label property.
        /// </summary>
        /// <value>
        /// The label property.
        /// </value>
        [JsonProperty(PropertyName = "labelProp")]
        public string LabelProp { get; set; }

        /// <summary>
        /// Gets or sets the value property.
        /// </summary>
        /// <value>
        /// The value property.
        /// </value>
        [JsonProperty(PropertyName = "valueProp")]
        public string ValueProp { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="OptionsTemplateOptionsAttribute"/> class.
        /// </summary>
        public OptionsTemplateOptionsAttribute()
        {
            this.LabelProp = "name";
            this.ValueProp = "value";
        }
    }
}
